import React from 'react';
import axios from '../../req/index';
import { Form, Field, Button } from 'react-vant';
import { Toast } from 'react-vant';
const Login = (routerProps) => {
  const [form] = Form.useForm();
  const onFinish = (values) => {
    axios.post('/logins', {
      values
    }).then((res) => {
      if (res.data.code === 1) {
        Toast.success('登陆成功');
        window.localStorage.setItem('isLogin', 'true')
        setTimeout(() => {
          routerProps.history.replace('/defaultPage/home')
        }, 200)
      } else {
        Toast.fail('登陆失败');
      }
    })
  };
  return (
    <Form colon onFinish={onFinish} form={form} border >
      <Form.Item name="username" label="用户名" >
        <Field placeholder='请输入用户名' />
      </Form.Item>
      <Form.Item name="password" label="密码">
        <Field placeholder='请输入密码' />
      </Form.Item>
      <Button round nativeType="submit" type="primary" block>
        提交
      </Button>
    </Form>
  );
};
export default Login